home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 41
/
Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso
/
-seriously_amiga-
/
programming
/
other
/
gui4cli
/
tools
/
rtn
/
getfiletype
< prev
next >
Wrap
Text File
|
1999-04-29
|
6KB
|
251 lines
G4C
; GetFileType
; Created by dck, extended by Brian Jones
; -------------------------------------------------------------
; This routine tries to recognise the type of a given file.
; When it returns, $$RET.0 will contain the type of file that
; "FileName" was, or "NONE" if there was no file, or "UNKNOWN"
; if the file was not one of the various filetypes defined
; below (to which you can easily add..)
; -------------------------------------------------------------
xONLOAD filename
guiopen GetFileType $filename
xONRELOAD filename
guiopen GetFileType $filename
xONOPEN filename ; this is the main routine
if $filename = ''
return 'NONE'
endif
; -------------------------------------------------------------
; First we check the Header - We do this in a subroutine
; because we want to set deeptrans on again before we return
; -------------------------------------------------------------
GOSUB getfiletype Check_Header ; check header (end of this file)
type = $$ret.0 ; store the file type
set deeptrans on
if $type != UNKNOWN ; did we find it ?
return $getfiletype/type ; yes - return *full* variable path
endif
; otherwise, continue with checking file extension
extract filename ext rtn.ext ; get extension
if $rtn.ext != ""
docase $rtn.ext
case == ".info"
return INFO
case == ".txt"
case == ".doc"
case == ".readme"
case == ".man"
return TEXT
case == ".guide"
return GUIDE
case == ".ilbm"
case == ".24"
case == ".iff"
return ILBM
case == ".gif"
return GIF
case == ".tga"
return TGA ; or GFX or DT
case == ".ppm"
return PPM ; or DT if you've got the V43 picture.datatype and the new ppm datatype
case == ".bmp" ;
case == ".pcx" ; the return for these could be GFX or DT
case == ".pbm" ; as there are datatypes for all of them
case == ".pgm" ;
case == ".png" ;
case == ".tiff"
return GFX ; DT - take your pick
case == ".qrt" ; qrt could go under GFX or DT but its datatype interferes with the system so I put it here
case == ".sgi" ; the only program that I have (or trust for .qrt) to
case == ".vmem" ; open these is ImageStudio so I put these here.
return GFXED
case == ".font"
return FONT
case == ".qt"
case == ".mov"
return QT
case == ".anim"
return ANIM
case == ".S3M"
case == ".mod"
case == ".XM"
case == ".med"
case == ".ocss"
case == ".digi"
case == ".tune"
return MOD
case == ".8svx"
case == ".16vx"
case == ".wav"
case == ".aiff"
case == ".au"
case == ".snd"
return SMPL
case == ".lha"
case == ".lzh"
return LHA
case == ".lzx"
return LZX
case == ".html"
case == ".htm"
case == ".index"
return HTML
case == ".fli"
case == ".flc"
return FLC
case == ".mpg"
case == ".mpeg"
return MPG
case == ".avi"
return AVI
endcase
endif
; still haven't found it..
extract filename file rtn.temp ; see if it's a module
cutvar rtn.temp copy char 4 rtn.mod
if $rtn.mod == mod.
return MOD
endif
set deeptrans off
if $header S= "##########" ; a text file (probably)
set deeptrans on
return TEXT
endif
set deeptrans on
return UNKNOWN ; end of GetFileType - nothing found..
; -------------------------------------------------------------
; This routine checks the filetype by comparing the file header.
; To do this faster than with H=, we use the ReadVar command.
; Note that we have to turn off DEEPTRANS so that we don't have
; translation of the header since it may contain $ characters
; which would confuse the hell out of it.
; -------------------------------------------------------------
xROUTINE Check_Header
readvar $filename 0 100 header ; read the header
set deeptrans off
if $header S= "XPKF" ; advance header behind an
cutvar header cut char 16 temp ; XPK'd files xpk header.
endif
docase $header
case S= "G4C" ; Yes.. you guessed it.
return G4C
case S= "@D" ; Amigaguide (probably)
case S= "@d"
return GUIDE
case S= "ã" ; icon
return INFO
case S= "FORM????ILBM" ; ILBM
case S= "FORM???ILBM"
case S= "FORM??ILBM"
return ILBM
case S= "GIF" ; GIF
return GIF
case S= "??????JFIF" ; JPEG
case S= "ÿØÿÄ" ; JPEG
return JPG
case S= "?PNG" ; PNG
return PNG
case S= "P4" ; PBM
case S= "P5" ; PGM
case S= "BM" ; BMP
case S= "MM" ; TIFF - I'm not entirely sure about this since I have only one TIFF writer
return GFX ; again or DT
case S= "P6" ; PPM
return PPM
case S= "FORM????DEEP" ; IFF-Deep
case S= "??VMEM" ; ImageStudio VMEM and header
return GFXED ; ImageStudio is all I know that will handle these
case S= "FORM????ANIM" ; Animation
case S= "FORM???ANIM"
return ANIM
case S= "????mdat" ; QuickTime animation
return QT
case S= "MMD" ; MED
case S= "Extended Module:" ; XM
case S= "????????????????????????????????????????????SCRM" ; S3M Scream Tracker 3
case S= "?????????????????????????????????????????????@" ; Hope it's not a guide
case S= "DIGI Booster"
return MOD
case S= "FORM????8SVX" ; 8svx Sound sample
return 8SVX ; try gcsound - otherwise SMPL
case S= "FORM????16VX" ; 16vx Sound sample
case S= "FORM????AIFF" ; AIFF Sound sample
case S= "RIFF????WAVE" ; Wav Sound sample
case S= ".snd" ; .au Sound sample (I think, I've only got one)
return SMPL
case S= "PP" ; PowerPacked file
return PP
case S= "??-lh" ; LhA
return LHA
case S= "LZX" ; LZX
return LZX
case S= "ZOO ?.??" ; zoo
return ZOO
case S= "PK" ; unzip
return ZIP
case S= "%%%ó%" ; executable
return EXE
endcase
return UNKNOWN